package cn.taokuaidi.wangwang.client.data;

import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.URL;

/**
 * 所有远程请求集散地
 * 
 * @author 嘉陵江里捉鱼
 */
public class Request {

    public static RequestBuilder getSellerBuilder() {
        String url = "/gwt_seller/";
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }

    public static RequestBuilder getBuyerBuilder() {
        String url = "/gwt_buyer/";
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }

    public static RequestBuilder getAgents() {
        String url = "/gwt_seller/agent";
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }

    public static RequestBuilder getCharts() {
        String url = "/chart/data";
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }

    public static RequestBuilder saveNo(boolean isSeller, String orderId, String agentId, String no) {
        if (isSeller) {
            return sellerSaveNo(orderId, agentId, no);
        }
        return buyerSaveNo(orderId, agentId, no);
    }

    private static RequestBuilder sellerSaveNo(String orderId, String agentId, String no) {
        String url = "/gwt_seller/saveno?agent_id=" + agentId + "&no_code=" + no + "&order_id=" + orderId;
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }

    private static RequestBuilder buyerSaveNo(String orderId, String agentId, String no) {
        String url = "/gwt_buyer/saveno?agent_id=" + agentId + "&no_code=" + no + "&order_id=" + orderId;
        return new RequestBuilder(RequestBuilder.GET, URL.encode(url));
    }
}
